<template>
  <div class="promotions-page">
    <Header />
    
    <main class="main">
      <div class="container">
        <div class="promotions-header">
          <h1 class="promotions-title">优惠专区</h1>
          <p class="promotions-subtitle">限时特价，品质保证</p>
        </div>

        <div class="promotions-content">
          <div class="promotion-banner">
            <div class="banner-content">
              <h2>年终大促</h2>
              <p>全场商品低至5折，限时抢购中</p>
              <div class="countdown">
                <span>距离结束还有：</span>
                <div class="countdown-timer">
                  <div class="time-unit">
                    <span class="time-value">{{ countdown.days }}</span>
                    <span class="time-label">天</span>
                  </div>
                  <div class="time-unit">
                    <span class="time-value">{{ countdown.hours }}</span>
                    <span class="time-label">时</span>
                  </div>
                  <div class="time-unit">
                    <span class="time-value">{{ countdown.minutes }}</span>
                    <span class="time-label">分</span>
                  </div>
                  <div class="time-unit">
                    <span class="time-value">{{ countdown.seconds }}</span>
                    <span class="time-label">秒</span>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="promotions-grid">
            <div 
              class="promotion-card" 
              v-for="promotion in promotions" 
              :key="promotion.id"
              @click="handlePromotionClick(promotion)"
            >
              <div class="promotion-image">
                <img :src="promotion.image" :alt="promotion.title">
                <div class="promotion-badge">{{ promotion.discount }}</div>
              </div>
              <div class="promotion-info">
                <h3 class="promotion-title">{{ promotion.title }}</h3>
                <p class="promotion-description">{{ promotion.description }}</p>
                <div class="promotion-price">
                  <span class="current-price">¥{{ promotion.currentPrice }}</span>
                  <span class="original-price">¥{{ promotion.originalPrice }}</span>
                </div>
                <div class="promotion-stats">
                  <span class="sales-count">已售 {{ promotion.salesCount }}</span>
                  <span class="stock">库存 {{ promotion.stock }}</span>
                </div>
                <button class="promotion-btn">立即抢购</button>
              </div>
            </div>
          </div>

          <div class="coupon-section">
            <h2 class="section-title">优惠券</h2>
            <div class="coupons-grid">
              <div 
                class="coupon-card" 
                v-for="coupon in coupons" 
                :key="coupon.id"
                @click="handleCouponClick(coupon)"
              >
                <div class="coupon-amount">
                  <span class="amount">¥{{ coupon.amount }}</span>
                  <span class="condition">满{{ coupon.condition }}可用</span>
                </div>
                <div class="coupon-info">
                  <h4>{{ coupon.title }}</h4>
                  <p>{{ coupon.description }}</p>
                  <span class="expiry">有效期至：{{ coupon.expiry }}</span>
                </div>
                <button class="coupon-btn">立即领取</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>

    <Footer />
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import Header from '@/components/Header.vue'
import Footer from '@/components/Footer.vue'

const countdown = ref({
  days: 0,
  hours: 0,
  minutes: 0,
  seconds: 0
})

// 模拟促销数据
const promotions = ref([
  {
    id: 1,
    title: 'iPhone 15 Pro 限时特价',
    description: '最新款iPhone，限时抢购，错过再等一年',
    currentPrice: '7,999',
    originalPrice: '9,999',
    discount: '8折',
    image: 'https://images.unsplash.com/photo-1592750475338-74b7b21085ab?w=400&h=400&fit=crop&crop=center',
    salesCount: '2.5k+',
    stock: 156
  },
  {
    id: 2,
    title: 'MacBook Air M3 芯片版',
    description: '轻薄便携，性能强劲，办公首选',
    currentPrice: '8,499',
    originalPrice: '10,999',
    discount: '7.7折',
    image: 'https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=400&h=400&fit=crop&crop=center',
    salesCount: '1.8k+',
    stock: 89
  },
  {
    id: 3,
    title: 'Sony WH-1000XM5 降噪耳机',
    description: '业界顶级降噪，音质出众',
    currentPrice: '2,199',
    originalPrice: '2,999',
    discount: '7.3折',
    image: 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=400&h=400&fit=crop&crop=center',
    salesCount: '3.2k+',
    stock: 234
  },
  {
    id: 4,
    title: 'Nike Air Max 270 React',
    description: '舒适缓震，时尚百搭',
    currentPrice: '599',
    originalPrice: '899',
    discount: '6.7折',
    image: 'https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=400&h=400&fit=crop&crop=center',
    salesCount: '4.1k+',
    stock: 567
  }
])

// 模拟优惠券数据
const coupons = ref([
  {
    id: 1,
    title: '新人专享券',
    description: '新用户专享，全场通用',
    amount: 50,
    condition: 299,
    expiry: '2024-12-31'
  },
  {
    id: 2,
    title: '数码专区券',
    description: '数码产品专用，限时发放',
    amount: 100,
    condition: 999,
    expiry: '2024-12-25'
  },
  {
    id: 3,
    title: '服饰专区券',
    description: '服饰箱包专用，数量有限',
    amount: 30,
    condition: 199,
    expiry: '2024-12-20'
  }
])

// 倒计时功能
let countdownTimer: number

const updateCountdown = () => {
  const now = new Date().getTime()
  const endTime = new Date('2024-12-31 23:59:59').getTime()
  const timeLeft = endTime - now

  if (timeLeft > 0) {
    const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24))
    const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
    const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60))
    const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000)

    countdown.value = { days, hours, minutes, seconds }
  } else {
    countdown.value = { days: 0, hours: 0, minutes: 0, seconds: 0 }
  }
}

// 处理促销点击
const handlePromotionClick = (promotion: any) => {
  alert(`抢购商品：${promotion.title}`)
}

// 处理优惠券点击
const handleCouponClick = (coupon: any) => {
  alert(`领取优惠券：${coupon.title}`)
}

onMounted(() => {
  updateCountdown()
  countdownTimer = setInterval(updateCountdown, 1000)
})

onUnmounted(() => {
  if (countdownTimer) {
    clearInterval(countdownTimer)
  }
})
</script>

<style scoped>
.promotions-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.promotions-header {
  text-align: center;
  margin-bottom: 40px;
}

.promotions-title {
  font-size: 32px;
  font-weight: 700;
  color: #2d3436;
  margin-bottom: 10px;
}

.promotions-subtitle {
  font-size: 16px;
  color: #636e72;
}

.promotions-content {
  max-width: 1200px;
  margin: 0 auto;
}

.promotion-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 16px;
  padding: 40px;
  margin-bottom: 40px;
  color: white;
  text-align: center;
}

.banner-content h2 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 10px;
}

.banner-content p {
  font-size: 18px;
  margin-bottom: 30px;
  opacity: 0.9;
}

.countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.countdown span {
  font-size: 16px;
  opacity: 0.9;
}

.countdown-timer {
  display: flex;
  gap: 15px;
}

.time-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.2);
  padding: 15px;
  border-radius: 12px;
  min-width: 60px;
}

.time-value {
  font-size: 24px;
  font-weight: 700;
}

.time-label {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 5px;
}

.promotions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

.promotion-card {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
  cursor: pointer;
}

.promotion-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 30px rgba(0,0,0,0.15);
}

.promotion-image {
  position: relative;
  height: 200px;
  overflow: hidden;
}

.promotion-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.promotion-card:hover .promotion-image img {
  transform: scale(1.05);
}

.promotion-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
  color: white;
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.promotion-info {
  padding: 20px;
}

.promotion-title {
  font-size: 18px;
  font-weight: 600;
  color: #2d3436;
  margin-bottom: 8px;
}

.promotion-description {
  font-size: 14px;
  color: #636e72;
  margin-bottom: 12px;
  line-height: 1.4;
}

.promotion-price {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.current-price {
  font-size: 20px;
  font-weight: 700;
  color: #e74c3c;
}

.original-price {
  font-size: 14px;
  color: #bdc3c7;
  text-decoration: line-through;
}

.promotion-stats {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #95a5a6;
  margin-bottom: 16px;
}

.promotion-btn {
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.promotion-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.coupon-section {
  margin-top: 40px;
}

.section-title {
  font-size: 24px;
  font-weight: 600;
  color: #2d3436;
  margin-bottom: 20px;
  text-align: center;
}

.coupons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.coupon-card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.coupon-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.coupon-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.coupon-amount {
  text-align: center;
  min-width: 80px;
}

.coupon-amount .amount {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: #e74c3c;
}

.coupon-amount .condition {
  font-size: 12px;
  color: #636e72;
}

.coupon-info {
  flex: 1;
}

.coupon-info h4 {
  font-size: 16px;
  font-weight: 600;
  color: #2d3436;
  margin-bottom: 4px;
}

.coupon-info p {
  font-size: 12px;
  color: #636e72;
  margin-bottom: 8px;
}

.coupon-info .expiry {
  font-size: 11px;
  color: #95a5a6;
}

.coupon-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.coupon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

@media (max-width: 768px) {
  .promotion-banner {
    padding: 30px 20px;
  }
  
  .banner-content h2 {
    font-size: 24px;
  }
  
  .countdown-timer {
    gap: 10px;
  }
  
  .time-unit {
    padding: 10px;
    min-width: 50px;
  }
  
  .time-value {
    font-size: 18px;
  }
  
  .promotions-grid {
    grid-template-columns: 1fr;
  }
  
  .coupons-grid {
    grid-template-columns: 1fr;
  }
  
  .coupon-card {
    flex-direction: column;
    text-align: center;
  }
}
</style> 